package edu.unice.simul.vue.components.simul;

import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import edu.unice.simul.controleur.interfaces.SpeedControlerI;

public class SpeedSlider extends JSlider {
	private static final long serialVersionUID = 401015590022397167L;
	
	private SpeedControlerI controleur;
	
	public SpeedSlider(SpeedControlerI controleur) {
		super(JSlider.HORIZONTAL, 1, 5, 3);
		this.controleur = controleur;
		
		buildUI();
		
		addChangeListener(new ChangeListener() {
			@Override
			public void stateChanged(ChangeEvent ev) {
				SpeedSlider.this.controleur.setSpeed(getValue());
			}
		});
	}
	
	private void buildUI() {
		setMajorTickSpacing(1);
		setMinorTickSpacing(1);
		setPaintTicks(true);
		setPaintLabels(true);
		setSnapToTicks(true);
	}
}
